<?php
function writeInfile($fileName,$str){
$File = $fileName;
$fh = fopen($File, 'w');
fwrite($fh, $str);
fclose($fh);
}

include('includes/dbConnection.php');
$presID='1'; // current presentation
$sqlQuery=mysql_query("SELECT * FROM presentations where presID=$presID") or die(mysql_error());
$rs=mysql_fetch_assoc($sqlQuery);

//while ($rs=mysql_fetch_assoc($sqlQuery)) {
                         
$presID=$rs['presID'];
$presTitle= $rs['presTitle'];
$slideNum=$rs['slideNum'];
//echo 'slidenum' .$slideNum;// $rs['slideNum'];//$slidenum;

$sqlQuery=mysql_query("SELECT * FROM slides where presID=$presID") or die(mysql_error());
;
//$rs=mysql_fetch_assoc($sqlQuery);
$i=1;
$slideCaptions[$slideNum+1];
while ($rs=mysql_fetch_assoc($sqlQuery)) {
$slideCaptions[$i]=$rs['caption'];
//echo $i . ' ' . $slideCaptions[$i];
$i++;
}


exec('rm -r slides');
exec('mkdir -p slides/files');
exec('cp -r library slides/');
exec('cp -r library slides/');
exec('cp -r images slides/');
exec('cp -r scripts slides/');

$variablesJSstr="var lastSlideId=$slideNum;\n";
$variablesJSstr.="var slideCaption = new Array(lastSlideId+1);\n";
$variablesJSstr.="slideCaption[0]=\"\";\n";
for($i=1;$i<=$slideNum;$i++) $variablesJSstr.="slideCaption[$i]=\"$slideCaptions[$i]\";\n";
//echo " $slideCaptions[$i] \n";
writeInfile('slides/scripts/variables.js',$variablesJSstr);


$bpNum= $_GET["bpNum"]; //fromdatabase
//require('templates/index_head.tpl');
//$slideNum = 5; //from db
$pagestr="";
for($i=1;$i<=$slideNum;$i++){

	$pagestr.="<div id=$i  onclick='nextSlide(this);return false;'";
	if($i==1)
		$pagestr.= "class=slides style='display:block;' >";	
	else
		$pagestr.= "class=slides style='display:none;' >";	
	
	$pagestr.= "slide " .$i. "<br />";

//echo $bpNum.$i;

if($bpNum>0){
	
	
$pagestr.= "<ul>";

for($j=1;$j<=$bpNum;$j++){

	$pagestr.= " <li id='li_".$j."' style='font-size:large;'>Bullet point ".$j."asd asdasa iasd lumpus odila koneba hudu</li> ";
	
}

$pagestr.= "</ul>";
}
//echo '<script>alert(2);</script>';
$pagestr.= "</div>";
}
//echo $pagestr;
//include('templates/index_footer.tpl');
//$string= $_GET["str"]; //string from generate 
//echo $pagestr;
//require('generate.php?bpNum=7');
//exec('rm -r slides');
//exec('mkdir -p slides/files');
//exec('cp -r library slides');
//exec('cp -r library slides');
//exec('cp -r images slides/');
//exec('cp -r scripts slides');
exec('cat templates/index_head.tpl > slides/index.html');
//echo $pagestr;
$myFile = "slides/slides.html";
$fh = fopen($myFile, 'w');
fwrite($fh, $pagestr);
fclose($fh);

exec('cat slides/slides.html >> slides/index.html');
exec('cat templates/index_footer.tpl >> slides/index.html');
exec('tar -cvf slides/slides.tar slides/');

//echo exec('ls -l slides/') . "\n";
?>

<a href="slides/slides.tar">Download Slides as tar ball</a>
<a href="slides/" target=_blank> See Slides</a>
